package com.sunkyc.controller.system;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sunkyc.commons.annotation.ReqLog;
import com.sunkyc.commons.entity.R;
import com.sunkyc.framework.system.entity.SysDept;
import com.sunkyc.framework.system.service.SysDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 组织管理 前端控制器
 * </p>
 *
 * @author sunkyc
 * @since 2022-05-31
 */
@RestController
@RequestMapping("/sysDept")
@Api(value = "组织管理前端控制器", tags = {"组织管理"})
@RequiredArgsConstructor
public class SysDeptController {
    private final SysDeptService baseService;

    @GetMapping("/treeList")
    @ApiOperation("查询前端组织树形结构数据")
    @SaCheckPermission("system-dept-list")
    public R<List<SysDept>> deptTree(){
        return R.ok(baseService.treeList());
    }

    @GetMapping("/{deptId}")
    @ApiOperation("根据父组织机构ID的查询当前子组织列表")
    @SaCheckPermission("system-dept-query")
    public R<List<SysDept>> deptListByParentId(@PathVariable Long deptId){
        return R.ok(baseService.deptListByParentId(deptId));
    }


    @PostMapping
    @ApiOperation("组织添加")
    @SaCheckPermission("system-dept-add")
    @ReqLog
    public R<Void> addDept(@RequestBody @Validated SysDept sysDept){
        return R.result(baseService.addDept(sysDept));
    }


    @PutMapping
    @ApiOperation("组织修改")
    @SaCheckPermission("system-dept-update")
    @ReqLog
    public R<Void> updateDept(@RequestBody @Validated SysDept sysDept){
        return R.result(baseService.updateDept(sysDept));
    }


    @DeleteMapping("/{ids}")
    @ApiOperation("组织删除")
    @ReqLog
    @SaCheckPermission("system-dept-delete")
    public R<Void> delDeptByIds(@PathVariable("ids") Long[] ids){
        return R.result(baseService.delDeptByIds(ids));
    }






}
